package org.jeecg.modules.biz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.biz.entity.BurnCashOutApply;
import org.jeecg.modules.biz.entity.BurnIncome;
import org.jeecg.modules.biz.mapper.BurnCashOutAppleMapper;
import org.jeecg.modules.biz.service.BurnCashOutAppleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class BurnCashOutAppleServiceImpl extends ServiceImpl<BurnCashOutAppleMapper, BurnCashOutApply> implements BurnCashOutAppleService {
    @Autowired
    private BurnCashOutAppleMapper cashOutAppleMapper;
    @Autowired
    private BurnIncomeServiceImpl incomeService;

    @Override
    @Transactional
    public boolean updateAndFreezingAmount(String address, Long balance) {
        // 冻结资金
        BurnIncome burnIncome = new BurnIncome();
        burnIncome.setFreezingAmount(balance);

        incomeService.update(burnIncome, new QueryWrapper<BurnIncome>().eq("address", address));

        // 更新状态
        BurnCashOutApply burnCashOutApply = new BurnCashOutApply();
        burnCashOutApply.setIsExamine(true);
        this.update(burnCashOutApply, new QueryWrapper<BurnCashOutApply>().eq("address", address));
        return true;
    }

    @Override
    public IPage<Map<String, Object>> findList4Examine(Page<Map<String, Object>> page) {
        return cashOutAppleMapper.findList4Examine(page);
    }
}
